﻿using System;
using PostSharp.Laos;

namespace FutureVision.Infrastructure
{
    [Serializable]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
    public class LogRoutineAspect : OnMethodBoundaryAspect
    {
        public LogRoutineAspect(string entryMessage)
        {
            this.EntryMessage = entryMessage;
        }

        public string EntryMessage { get; set; }
        public string ExitMessage { get; set; }

        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            if (!String.IsNullOrEmpty(this.EntryMessage))
            {
                LogService.Default.Info(this.EntryMessage);
            }

            base.OnEntry(eventArgs);
        }

        public override void OnExit(MethodExecutionEventArgs eventArgs)
        {
            if (!String.IsNullOrEmpty(this.ExitMessage))
            {
                LogService.Default.Info(this.ExitMessage);
            }

            base.OnExit(eventArgs);
        }
    }
}